import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:recipes/main/global/uiconfig/size_fit.dart';

import 'generated/l10n.dart';
import 'main/global/provider/favor_provider.dart';
import 'main/global/router/router.dart';
import 'main/global/tools/hud/hud_manager.dart';
import 'main/global/uiconfig/app_theme.dart';
import 'main/global/provider/meal_list_provider.dart';
import 'main/global/provider/filter_provider.dart';

void main() {
  runApp(MultiProvider(providers: [
    ChangeNotifierProvider(create: (_) => YSHFavorProvider()),
    ChangeNotifierProvider(create: (_) => YSHFilterProvider()),
    ChangeNotifierProxyProvider<YSHFilterProvider, YSHMealListProvider>(
        create: (_) {
          return YSHMealListProvider();
        },
        update: (_, favorProvider, mealProvider) =>
        YSHMealListProvider()..updateFilters(favorProvider)),
  ], child: const MyApp()));
  YSHHUDManager.configHUDManager();
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    YSHSizeFit.initialize();
    return MaterialApp(
      title: '美食谱',
      theme: YSHAppTheme.lightThemeData,
      darkTheme: YSHAppTheme.darkThemeData,
      routes: YSHRouter.routes,
      initialRoute: YSHRouter.initialRoute,
      onGenerateRoute: YSHRouter.generateRoute,
      onUnknownRoute: YSHRouter.unknownRoute,
      supportedLocales: S.delegate.supportedLocales,
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        RefreshLocalizationsDelegate(),
        S.delegate
      ],
      debugShowCheckedModeBanner: false,
      builder: YSHHUDManager.initHUDTool(),
    );
  }
}
